package com.kelvin.paopao.module.peisong.mypeisong.peisongperson;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.kelvin.paopao.R;
import com.kelvin.paopao.adapter.DatePersonAdapter;
import com.kelvin.paopao.adapter.PeisongPersonAdapter;
import com.kelvin.paopao.api.responseBean.DatePersonModel;
import com.kelvin.paopao.api.responseBean.UserDetailModel;
import com.kelvin.paopao.injector.components.DaggerDatePersonComponent;
import com.kelvin.paopao.injector.components.DaggerPeisongPersonComponent;
import com.kelvin.paopao.injector.modules.DatePersonModule;
import com.kelvin.paopao.injector.modules.PeisongPersonModule;
import com.kelvin.paopao.module.base.BaseActivity;
import com.kelvin.paopao.module.main.date.dateperson.IDatePersonPresenter;
import com.kelvin.paopao.module.main.date.dateperson.IDatePersonView;
import com.kelvin.paopao.module.peisong.list.IPeisongListView;
import com.kelvin.paopao.module.person.detail.PersonDetailActivity;
import com.kelvin.paopao.widgets.CustomToolbar;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * Created by Administrator on 2017/5/16.
 */

public class PeisongPersonActivity extends BaseActivity<IPeisongPersonPresenter>
        implements IPeisongPersonView {

    @BindView(R.id.custom_toolbar)
    CustomToolbar customToolbar;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    private LinearLayoutManager manager;
    private String id;

    @Inject
    PeisongPersonAdapter peisongPersonAdapter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_date_person;
    }

    @Override
    protected void initInjector() {
        DaggerPeisongPersonComponent.builder().peisongPersonModule(new PeisongPersonModule(this))
                .build().inject(this);
    }

    @Override
    protected void initViews() {
        customToolbar.showBackIcon(this);
        id = getIntent().getStringExtra("id");
        manager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(manager);
        peisongPersonAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                if (peisongPersonAdapter.isCanCheck()) {
                    mPresenter.peisong(((UserDetailModel) adapter.getData().get(position)).getUser_no(),
                            String.valueOf(id));
                }
            }
        });
        recyclerView.setAdapter(peisongPersonAdapter);
    }

    @Override
    protected void updateViews(boolean isRefresh) {
        mPresenter.getPeisongPerson(String.valueOf(id));
    }

    /**
     * 進入申請邀約人的界面
     *
     * @param context
     */
    public static void launch(Context context, String id) {
        Intent intent = new Intent(context, PeisongPersonActivity.class);
        intent.putExtra("id", id);
        context.startActivity(intent);
    }

    @Override
    public void loadData(List<UserDetailModel> models) {
        peisongPersonAdapter.setNewData(models);
    }

    @Override
    public void showNoData() {
        View nodataView = LayoutInflater.from(this).inflate(R.layout.view_no_data,
                (ViewGroup) recyclerView.getParent(), false);
        peisongPersonAdapter.setEmptyView(nodataView);
    }

    @Override
    public void loadCheck(boolean isCanCheck) {
        peisongPersonAdapter.setCanCheck(isCanCheck);
        peisongPersonAdapter.notifyDataSetChanged();
    }
}
